﻿#include <iostream>
#include <string>
using namespace std;
class SalesItem 
{
private:
	string bookNo;
	int unitsSold;
	double sellingPrice;
	double salePrice;
	double discount;

public:
	// 构造函数
	SalesItem() : bookNo(""), unitsSold(0), sellingPrice(0.0), salePrice(0.0), discount(0.0) 
	{}

	// 获取ISBN的方法
	const string& getISBN() const 
	{
		return bookNo;
	}

	void inputBookInfo() 
	{
		cout << "Enter ISBN: ";
		cin >> bookNo;
		cout << "Enter units sold: ";
		cin >> unitsSold;
		cout << "Enter original price: ";
		cin >> sellingPrice;
		cout << "Enter sale price: ";
		cin >> salePrice;
		cout << "Enter discount: ";
		cin >> discount;
	}

	void outputBookInfo() const 
	{
		cout << "ISBN: " << bookNo << ", Units Sold: " << unitsSold << ", Original Price: " << sellingPrice << ", Sale Price: " << salePrice << ", Discount: " << discount << '\n';
	}

	// 赋值运算符重载
	SalesItem& operator=(const SalesItem& other) 
	{
		if (this != &other) 
		{
			bookNo = other.bookNo;
			unitsSold = other.unitsSold;
			sellingPrice = other.sellingPrice;
			salePrice = other.salePrice;
			discount = other.discount;
		}
		return *this;
	}

	// 合并两个SalesItem对象
	void combine(const SalesItem& other) 
	{
		if (bookNo == other.bookNo) 
		{
			unitsSold += other.unitsSold;		
		}
	}

	static void mainLoop() 
	{
		SalesItem item1, item2;
		item1.inputBookInfo();
		item2.inputBookInfo();

		if (item1.getISBN() == item2.getISBN()) 
		{
			item1.combine(item2);
			item1.outputBookInfo();
		}
		else {
			cout << "Cannot combine items with different ISBNs.\n";
		}
	}
};

int main() 
{
	SalesItem::mainLoop();
	return 0;
}